package edu.gyc.security.controller;

import edu.gyc.security.exception.UserNotExistException;
import edu.gyc.security.model.Girl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/girl")
@Slf4j
public class GirlController {

    @PostMapping
    public Object create(Girl girl) {
        log.info(girl.toString());
        return girl;
    }
    @PostMapping("/sex")
    public Object sex(@Valid @RequestBody Girl girl, BindingResult errors) {
        if (errors.hasErrors()) {
            errors.getAllErrors().stream().forEach(error-> System.out.println(error.getDefaultMessage()));
        }
        log.info("Your whore: "+girl.toString());
        return girl;
    }

    @PutMapping("/{id:\\d+}")
    public Object update(@PathVariable String id) {
        log.info("update {}",id);
        return "UPdate";
    }

    @DeleteMapping("/{id:\\d+}")
    public Object del(@PathVariable Integer id) {
        log.info("del {}", id);
        return "del";
    }


    @GetMapping("/{id:\\d+}")
    public Object getGirl(@PathVariable String id) {
       // throw new UserNotExistException(id);

        throw new RuntimeException("hi runtimeexception");
       // log.info("called getUserinfo");
       // return new Girl(7, "赵雨静", "123456", 889);
    }
}
